package com.example.springboot.pattern.state;

import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2021/10/11
 **/
public class State {
    /**
     * 状态编码
     */
    @Getter
    private String stateCode;

    /**
     * 当前状态下可允许执行的动作
     */
    @Getter
    private List<Transition> transitions = new ArrayList<>();

    public State(String stateCode, Transition ... transitions) {
        this.stateCode = stateCode;
        this.transitions.addAll(Arrays.asList(transitions));
    }


    /**
     * 添加动作
     *
     * @param transition
     */
    public void addTransition(Transition transition) {
        transitions.add(transition);
    }

    @Override
    public String toString() {
        return stateCode;
    }

}
